package com.cloudkinto.controller.material;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.material.MaterialQueryBo;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.entity.MaterialDo;
import com.cloudkinto.service.material.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * <p>
 * 包材 前端控制器
 * </p>
 *
 * @author long
 * @since 2024-12-03
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "包材模块")
@RequestMapping("/api/admin/oms/material")
public class MaterialOmsController extends BaseController {
    private final MaterialService materialService;

    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "包材根据id查看详情", notes = "包材根据id查看详情")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = MaterialDo.class))
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", materialService.detail(id));
    }

    @UserSessionRequired
    @PostMapping("/listPage")
    @ApiOperation(value = "包材查询（分页）", notes = "包材查询（分页）")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = MaterialDo.class))
    public PageResult listPage(@RequestBody @Validated MaterialQueryBo bo) {
        if (Objects.isNull(bo.getWhId())) {
            bo.setWhId(getWarehouseId());
        }
        bo.setTenantId(getTenantId());
        return materialService.getListPage(bo);
    }
}

